<template>
	<view class="conts">
		<view class="navw">
			
			<view class="viewbody" >
				<view @click="cbclick(0)" :class="[viewbodys[0]? 'viewboottom':'']">通讯录</view>
			</view>
			<view class="viewbody" >
				<view @click="cbclick(1)" :class="[viewbodys[1]? 'viewboottom':'']">个人收藏</view>
			</view>
			<view class="viewbody" >
				<view @click="cbclick(2)" :class="[viewbodys[2]? 'viewboottom':'']">组织机构</view>
			</view>
		</view>
		
		<view class="content" v-if="content">
			
			<!-- 使用content2的插件 -->
			
			 <view class="example-body">
					    <!-- 搜索插件 -->
					<uni-search-bar radius="100" placeholder="输入姓名" @confirm="searcont" />
			</view>
			
			<view>
				<SortPickerList ref="sortPickerListCont" @clickData="clickDataCont"></SortPickerList>
					
			</view>
			
		</view>
		
		
		<view class="content2" v-if="content2">
		    <view class="example-body">
		    <!-- 搜索插件 -->
		    	<uni-search-bar radius="100" placeholder="输入姓名" @confirm="search" />
		    </view>
		
			<view>
				<SortPickerList ref="sortPickerList" @clickData="clickData"></SortPickerList>
		
			</view>
		</view>
		
		
	</view>
</template>

<script>
    import SortPickerList from "../../components/nickro-sortPickerList/nickro-sortPickerList.vue"
    var that;
	
	var platform = uni.getSystemInfoSync().platform
	export default {
		components: {
			SortPickerList
		},
		data() {
			return {
				viewbodys:[true,false,false],
				content:true,
				content2:false,				
				dataArrCont: [],
				dataArr: [],
				pathHost:""

			}
		},
		onShow(){
			
			//http://192.168.1.106:8088/ggcapp//sys/user/list
		},
		onLoad() {
			that = this;
			//检查是否登录im
			let user=uni.getStorageSync("userInfo"); 
			that.$jjim.config(user.data.body.username,user.data.body.pwd);
			that.$jjim.login().then(function(dat){});
			const val = uni.getStorageSync("pathHost");
			that.pathHost=val;
			const res = uni.getSystemInfoSync();
			this.barHeight = res.windowHeight / 27;
			/* setTimeout(function(){
				  that.$refs["sortPickerListCont"].initPage(that.dataArrCont)
			},300);	 */
			
		   /* 通讯录*/
			try {
			    const value = uni.getStorageSync("JSESSIONID")
			    if (value) {
			        uni.request({
			       	url: that.pathHost+'/ggcapp/sys/user/list'+";JSESSIONID="+value+"?__ajax=true&mobileLogin=true&pageSize=999" ,
			       	success(data) {
						
					  	
							for (var i = 0; i < data.data.rows.length; i++) {
							 
								 that.dataArrCont.push({
									  id: data.data.rows[i].id+"",
									  name: data.data.rows[i].name+"",
									  value: data.data.rows[i].phone+"",
									  ptName:data.data.rows[i].office.name+"",
									  institution:data.data.rows[i].company.name+"",
									  imgPath:that.pathHost+""+data.data.rows[i].photo+""	,
									  typeInfo:1,
									  loginName:data.data.rows[i].loginName+""
								}) 
	
							}
							 setTimeout(function(){
								// console.log(that.dataArrCont)
								  that.$refs["sortPickerListCont"].initPage(that.dataArrCont);
							},100);	 
							
			       		}
			       })
			    }
			} catch (e) {
			   uni.showToast({
			   	title: 'erro',
			     duration: 2000
			   })
			}
			
			
			
		},
		onReady() {

		},
		//监听导航栏 点击事件
		onNavigationBarButtonTap(e) {
		    console.log("success")   
			//console.log(e) 
			let user=uni.getStorageSync("userInfo");
			that.$jjim.config(user.data.body.username,user.data.body.pwd);
			that.$jjim.login().then(function(dat){});
			uni.navigateTo({
				url: '../addressList/groupList'
			}) 
		 
		},
		onPageScroll: function(Object) {
		 // console.log(Object.scrollTop);//实时获取到滚动的值 
		},
		methods: {
			//点击个人收藏联系人
			clickData:function(data) {
				//console.log(data)
				uni.navigateTo({
					url: '../addressList/info?data='+JSON.stringify(data)
				}) 
			},
			//点击通讯录联系人
			clickDataCont:function(data) {
		
				//console.log('获取全部值：' + JSON.stringify(data)) 
				uni.navigateTo({
					// url: '../addressList/info?name='+data.label+"&phone="+data.value
							url: '../addressList/info?data='+JSON.stringify(data)
				}) 
				
			},
			//个人收藏搜索 
			search(res) {
		   //  console.log("个人收藏搜索 "+JSON.stringify(res))
		   uni.showToast({
		   	title: '搜索中....'+res.value,
		     duration: 2000
		   })
			try {
			    const value = uni.getStorageSync("JSESSIONID");
				that.dataArr=[];
			    if (value) {
			        uni.request({
			       	url: that.pathHost+'/ggcapp/userprojects/userenshrine/userEnshrine/data'+";JSESSIONID="+value+"?__ajax=true&mobileLogin=true&uname="+res.value+"&pageSize=999" ,
			       	success(data) {
						//console.log(data)
							for (var i = 0; i < data.data.rows.length; i++) {	
								//console.log("id:"+data.data.rows[i].id+";uid:"+data.data.rows[i].uid)
								 that.dataArr.push({
									  id: data.data.rows[i].id+"", //此id是收藏表的id不是收藏人的id
									  name: data.data.rows[i].uname+"",
									  value: data.data.rows[i].utel+"",
									  ptName:data.data.rows[i].uprojcet+"",
									  institution:data.data.rows[i].uinstitution+"",
									  imgPath:""+data.data.rows[i].uimg+""	,
									  typeInfo:2,
									  loginName:data.data.rows[i].loginName+""
								}) 
				
							}
							 setTimeout(function(){
								  that.$refs["sortPickerList"].initPage(that.dataArr)
							},100);	 
							
			       		}
			       })
			    }
			} catch (e) {
			   uni.showToast({
			   	title: 'erro',
			     duration: 2000
			   })
			}
			
			
			
			},
			//通讯录搜索
			searcont(res) {
				
				uni.showToast({
					title: '搜索中....'+res.value,
				  duration: 2000
				})
				try {
				    const value = uni.getStorageSync("JSESSIONID")
					that.dataArrCont=[];
				    if (value) {
				        uni.request({
				       	url: that.pathHost+'/ggcapp/sys/user/list'+";JSESSIONID="+value+"?__ajax=true&mobileLogin=true&pageSize=999&name="+res.value ,
				       	success(data) {
								for (var i = 0; i < data.data.rows.length; i++) {
								  //    console.log(data.data.rows[i])
									 // console.log("------通讯录------")
									 that.dataArrCont.push({
										  id: data.data.rows[i].id+"",
										  name: data.data.rows[i].name+"",
										  value: data.data.rows[i].phone+"",
										  ptName:data.data.rows[i].office.name+"",
										  institution:data.data.rows[i].company.name+"",
										  imgPath: that.pathHost+""+data.data.rows[i].photo+""	,
										  typeInfo:1,
										  loginName:data.data.rows[i].loginName+""
									}) 
					
								}
								 setTimeout(function(){
									  that.$refs["sortPickerListCont"].initPage(that.dataArrCont)
								},100);	 
								
				       		}
				       })
				    }
				} catch (e) {
				   uni.showToast({
				   	title: 'erro',
				     duration: 2000
				   })
				}
		
	
			},
			cbclick:function(e){
				let v=[];
				for (var i = 0; i <this.viewbodys.length; i++) {
					if(e==i){			
						v.push(true)
					}else{
						v.push(false)
					}
				}
				this.viewbodys=v;
				if(e==0){
					this.content=true;
					this.content2=false;				
					 setTimeout(function(){
					 	  that.$refs["sortPickerListCont"].initPage(that.dataArrCont)
					 },100);		
				}
				if(e==1){
					// uni.showLoading({
					// 	title:"数据加载..",
					// 	mask:true	
					// })
					this.content=false;
					this.content2=true;
					 that.dataArr=[];
					 /* 个人收藏*/
					try {
					    const value = uni.getStorageSync("JSESSIONID")
					    if (value) {
					        uni.request({
					       	url: that.pathHost+'/ggcapp/userprojects/userenshrine/userEnshrine/data'+";JSESSIONID="+value+"?__ajax=true&mobileLogin=true&pageSize=999" ,
					       	success(data) {							
									for (var i = 0; i < data.data.rows.length; i++) {		
										//console.log("id:"+data.data.rows[i].id+";uid:"+data.data.rows[i].uid)
										 that.dataArr.push({
											  id: data.data.rows[i].id+"",
											  name: data.data.rows[i].uname+"",
											  value: data.data.rows[i].utel+"",
											  ptName:data.data.rows[i].uprojcet+"",
											  institution:data.data.rows[i].uinstitution+"",
											  imgPath:""+data.data.rows[i].uimg+""	,
											  typeInfo:2,
											  loginName:data.data.rows[i].loginName+""
										}) 
						
									}
									 setTimeout(function(){
										  that.$refs["sortPickerList"].initPage(that.dataArr);
										   // uni.hideLoading();
									},100);	 
									
					       		}
					       })
					    }
					} catch (e) {
					   uni.showToast({
					   	title: 'erro',
					     duration: 2000
					   })
					}
					
					
					
						/* setTimeout(function(){						
							   that.$refs["sortPickerList"].initPage(that.dataArr)
						},500);			 */	
				}
				if(e==2){
					uni.navigateTo({
						url: '../addressList/projectAddressList'
					})
				}
											
			}
			
		
		}
	}
</script>

<style>
	.conts{
		width: 100%;
		
	}
	.example-body{
		position: -webkit-sticky;
		position: sticky;
		top: 90rpx;
	}
   .navw{
	   width: 100%;
	   height: 90rpx;
	   position: -webkit-sticky;
	   position: sticky;
	   top: 0rpx;
	  z-index: 999;
   }
    .navw>.viewbody{
		float: left;
		width: 33.3%;
		height:90rpx;
		line-height: 90rpx;
	  background-color: white;
	  padding-left: 5%;
	  padding-top: 3px;
	}
   .viewbody>view{
	   text-align: center;
	   height: 100%;
	   width: 80%;
	  
   }
   .viewboottom{
	    border-bottom: 1px solid #71B6F7;
		color:#71B6F7 ;
   }
	.searchName{
	
	}
	
	.content2{
		
	}
	.content {
		
		
		
	}
	
	

</style>
